//
//  JKTextView.m
//  ZhiHuDaily
//
//  Created by albert on 16/8/18.
//  Copyright © 2016年 albert. All rights reserved.
//

#import "JKTextView.h"

@interface JKTextView ()
/** 占位label */
@property (nonatomic, weak) UILabel *placeHolderLabel;
@end

@implementation JKTextView

- (UILabel *)placeHolderLabel{
    if (!_placeHolderLabel) {
        UILabel *lb = [[UILabel alloc] init];
        [self addSubview:lb];
        
        lb.font = [UIFont systemFontOfSize:16];
        
        lb.text = @"不友善言论会被删除，深度讨论会被优先展示。";
        [lb sizeToFit];
        self.font = lb.font;
        _placeHolderLabel = lb;
    }
    return _placeHolderLabel;
}

- (instancetype)initWithFrame:(CGRect)frame textContainer:(NSTextContainer *)textContainer{
    if (self = [super initWithFrame:frame textContainer:textContainer]) {
        [self setup];
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder{
    if (self = [super initWithCoder:aDecoder]) {
        [self setup];
    }
    return self;
}

- (void)setup{
    [self addSubview:self.placeHolderLabel];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.placeHolderLabel.x = 5;
    self.placeHolderLabel.y = 8;
}

#pragma mark - 外部调用方法
/** 控制占位文字的显示和隐藏 */
- (void)textChange{
    self.placeHolderLabel.hidden = [self hasText];
}

#pragma mark - 更新皮肤
- (void)changeToNightSkin{ // 夜间
    self.backgroundColor = JKNightSkinColor;
    self.textColor = JKColor(186, 186, 186);
    self.placeHolderLabel.textColor = JKColor(68, 68, 68);
    self.keyboardAppearance = UIKeyboardAppearanceDark;
    [self resignFirstResponder];
    [self becomeFirstResponder];
}

- (void)changeToDaySkin{ // 白天
    self.placeHolderLabel.textColor = [UIColor lightGrayColor];
    self.textColor = [UIColor blackColor];
    self.backgroundColor = JKGlobalBgColor;
    self.keyboardAppearance = UIKeyboardAppearanceDefault;
    [self resignFirstResponder];
    [self becomeFirstResponder];
}
@end
